package cn.cloudreal.cbms.levelRule.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import cn.cloudreal.cbms.levelRule.dao.LevelRuleDao;
import cn.cloudreal.cbms.vo.LevelRule;

public class LevelRuleDaoImpl extends SqlMapClientDaoSupport implements LevelRuleDao
{

    private final String ADD_LevelRule = "levelRule.addLevelRule";
    private final String FIND_LevelRuleByPriceID = "levelRule.findLevelRuleByPriceID";
    private final String FIND_LevelRuleByPriceIDAndType = "levelRule.findLevelRuleByPriceIDAndType";
    private final String DEL_LevelRuleBYPriceID = "levelRule.delLevelRuleByPriceID";
    private final String DEL_LevelRuleBYPriceID_01 = "levelRule.delLevelRuleByPriceID_01";
    
    public int addLevelRule(LevelRule levelRule)
    {
        Integer id = (Integer) this.getSqlMapClientTemplate().insert(ADD_LevelRule, levelRule);
        return id;
    }

    
    public List<LevelRule> findLevelRuleByPriceID(int priceID){
        List<LevelRule> list = this.getSqlMapClientTemplate().queryForList(FIND_LevelRuleByPriceID,priceID);
        return list;
    }
    
    /**
     * 媒体详情页面
     * @param priceID
     * @param levelPromotionType
     * @return
     */
    public List<LevelRule> findLevelRuleByPriceIDAndType(int priceID,String levelPromotionType){
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("priceID", priceID);//媒体价格ID
        param.put("levelPromotionType", levelPromotionType);//阶梯额度类型
        List<LevelRule> list = this.getSqlMapClientTemplate().queryForList(FIND_LevelRuleByPriceIDAndType,param);
        return list;
    }
    
    /**
     * 根据媒体媒体价格和阶梯类型删除
     * @param priceID
     */
    public void delLevelRuleByPriceID(int priceID,String levelPromotionType){
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("priceID", priceID);//媒体价格ID
        param.put("levelPromotionType", levelPromotionType);//阶梯额度类型
        this.getSqlMapClientTemplate().delete(DEL_LevelRuleBYPriceID, param);
    }
    
    /**
     * 根据媒体媒体价格删除
     * @param priceID
     */
    public void delLevelRuleByPriceID_01(int priceID){
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("priceID", priceID);//媒体价格ID
        this.getSqlMapClientTemplate().delete(DEL_LevelRuleBYPriceID_01, param);
    }
}
